<template>
    <div class="staffDetails">
        <el-card shadow="never" style="border: none">
            <table-list v-if="!isLoading" ref="childComponent" :tableData="tableData" :paperFormtion="tableFromtiong"
            :questionData="questionData"/>
            <div class="staffDetails-item">
                <Pagination v-if="meta.total" :total="meta.total" :limit="meta.per_page" @pagination="pagination" />
            </div>
        </el-card>
    </div>
</template>
<script>
import TableList from './staffdetailsview/TableList.vue'
import Pagination from "@/components/Pagination";
import { getExamRecordDetails,getExamRecordStatistics,getTestExamination } from '@/api/examination'
export default {
    components:{
        TableList,
        Pagination
    },
    data() {
        return {
            id:'',
            type:1,
            tableData:[],
            isLoading:true,
            tableFromtiong:{},
            questionData:{},
            meta: {},
            paperData:{
                page: 1,
                paginate: null,
            }
        }
    },
    created() {
        this.id=this.$route.params.id
        this.getExamPaperDetails()
        this.getQuestionDetails()
        this.handleTestExamination()
    },
    methods: {
        // 获取员工考完试卷的详情
        async getExamPaperDetails(){
            const params={
                page:this.paperData.page,
                type:1
            }
            try {
                const res=await getExamRecordDetails(this.id,params)
                if (res.code===200) {
                    this.tableData=res.data.topic
                    this.tableFromtiong=res.data
                    this.isLoading=false
                    // this.$nextTick(() => {
                    //     this.$refs.childComponent.handleDataUpdate();
                    // });
                }
            } catch (err) {
                console.log(err);
            }
        },
        async getQuestionDetails(){
            const params={
                examinationId:this.$route.params.id
            }
            try {
                const res= await getExamRecordStatistics(params)
                this.questionData=res.data
                //console.log(res);
            } catch (error) {
                console.log(error);
            }
        },
        async  handleTestExamination(){
            try {
                const res= await getTestExamination(this.id)
                this.meta = res.meta
                //console.log(res);
            } catch (error) {
                console.log(error);
            }
        },
        pagination(page) {
            this.paperData.page = page.page;
            this.paperData.paginate = page.limit;
            console.log(this.paperData);
            this.getExamPaperDetails();
        },
    },
}
</script>
<style lang="scss" scoped>
.staffDetails{
    margin: 20px;
    background-color: #fff;
}
</style>